﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AutoCooker4
{
    /// <summary>
    /// 注意到，我们现在只收到了Son的My appetite is 90%， 并没有Mother的；
    /// 
    /// 这就是委托函数为什么一般为void的原因，因为委托链调用结束，只返回最后一个调用结果。
    /// 
    /// 解决方案：同步委托轮询， 深入到代理里面，轮询监听者列表，手工一个个调用：
    ///             (see AutoCooker5)
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            AutoCooker4 easyCooker = new AutoCooker4();

            easyCooker.started += new CookStartedReply(Mother.CookStartedReply);
            easyCooker.completed += new CookCompletedReply(Mother.CookCompletedReply);
            easyCooker.completed += new CookCompletedReply(Son.CookCompletedReply); 
            easyCooker.DoCook();
            
            // Compare with AutoCooker3, these two lines will get compile Error: 
            // The event 'AutoCooker4.AutoCooker4.completed' can only appear on the left hand side of += or -= (except when used from within the type 'AutoCooker4.AutoCooker4')	
            // easyCooker.completed = new CookCompletedReply(Son.CookCompletedReply); 
            // easyCooker.completed();             

            Console.ReadLine();
        }
    }
}
